package work.person.helper;

import com.google.common.base.Joiner;
import work.fram.JDBCConnect;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

//检查服务器
public class CheckHelper {



    //判断是否存在
    public static boolean exist(String table, String... condition) {
        return count(table, condition) > 0;
    }

    //获取一个jdbc的连接
    private static Statement statement = JDBCConnect.getStatement();

    public static int count(String table, String... condition) {

        try {
            ResultSet query = statement.executeQuery("select count(sysid) from " + table + "  where " + Joiner.on("and").join(condition));
            if (query.last()) {
                return query.getInt(1);
            } else {
                return 0;
            }


        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }


}
